package com.carrent.bus.service.impl;

import com.carrent.bus.domain.Car;
import com.carrent.bus.mapper.CarMapper;
import com.carrent.bus.service.CarService;
import com.carrent.bus.vo.CarVo;
import com.carrent.sys.utils.DataGridView;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class CarServiceImpl implements CarService {
    @Autowired
    private CarMapper carMapper;
    //查询所有
    @Override
    public DataGridView queryAllCar(CarVo carVo) {
        Page<Object> page = PageHelper.startPage(carVo.getPage(),carVo.getLimit());
        List<Car> data = carMapper.queryAllCar(carVo);
        return new DataGridView(page.getTotal(),data);
    }
    //增加
    @Override
    public void addCar(CarVo carVo) {
        carMapper.insertSelective(carVo);
    }
    //修改
    @Override
    public void updateCar(CarVo carVo) {
        carMapper.updateByPrimaryKeySelective(carVo);
    }
    //删除
    @Override
    public void deleteCar(String carnumber) {
        carMapper.deleteByPrimaryKey(carnumber);
    }
    //批量删除
    @Override
    public void deleteBatchCar(String[] ids) {
        for (String id:ids) {
            carMapper.deleteByPrimaryKey(id);
        }
    }
}
